<?php

namespace App\Http\Resources\Cruise\ShopSelfCheck\Merchant;

use App\Http\Resources\BaseResource;
use App\Models\Cruise\CruiseCheckSelfDetailModel;
use App\Models\Cruise\CruiseCheckSelfTaskModel;
use App\Models\Cruise\CruiseOrderModel;
use Illuminate\Http\Request;

class ReportListV2Resource extends BaseResource
{
    /**
     * Transform the resource into an array.
     *
     * @param Request $request
     * @return array
     */
    public function toArray($request): array
    {
        $this->formatExecuteTime();

        switch ($this->cruiseOrderRel->status){
            case CruiseOrderModel::STATUS_AUDIT_OK:
                $this->customState = CruiseOrderModel::STATUS_AUDIT_OK;
                break;
            case CruiseOrderModel::STATUS_AUDIT_ERROR:
                $this->customState = CruiseOrderModel::STATUS_AUDIT_ERROR;
                break;
            case CruiseOrderModel::STATUS_EXPIRED:
                $this->customState = CruiseOrderModel::STATUS_EXPIRED;
                break;
            default:
                $this->customState = CruiseOrderModel::STATUS_NOT_REVIEW;
                break;
        }

        return [
            "id"                   => $this->id,
            "shopId"               => $this->shopId,
            "templateType"         => $this->templateType,
            "sysTemplate"          => $this->sysTemplate,
            "taskId"               => $this->taskId,
            "date"                 => $this->date,
            "status"               => $this->status,
            "cruiseOrderId"        => $this->cruiseOrderId,
            "executeStartTime"     => $this->executeStartTime,
            "executeEndTime"       => $this->executeEndTime,
            "customState"          => $this->customState,
            "fullName"             => vsprintf("%s(%s)", [
                $this->cruiseCheckSelfTaskRel->name,
                $this->getExecuteDateText($this->cruiseCheckSelfTaskRel->rule)
            ]),
            "executeStartTimeText" => $this->executeStartTimeText,
            "executeEndTimeText"   => $this->executeEndTimeText,
            "rule"                 => $this->cruiseCheckSelfTaskRel->rule,
            "ruleText"             => CruiseCheckSelfTaskModel::RULE_TEXT[$this->cruiseCheckSelfTaskRel->rule] ?? "",
            "submitTime"           => $this->submitTime,
            "submitUid"            => $this->submitUid,
            "submitUsername"       => $this->submitUsername,
            "checkDetailsId"       => $this->checkDetailsId
        ];
    }
}
